This sounds like a situtation for a loop.
Here is a program that reads 15 numbers from NUMS.DAT and computes their sum.
OPEN "NUMS.DAT" FOR INPUT AS #7 ' Open the file LET SUM = 0 ' Initialize the sum LET COUNT = 1 ' Count from 1 to 15 DO WHILE COUNT <= 15 ' Loop once per count INPUT #7, NUM ' Read one number LET SUM = SUM + NUM ' Add it to the sum LET COUNT = COUNT + 1 ' Count up by one LOOP PRINT "SUM is", SUM ' Print out the results END
This is an ordinary loop that controls the number of times
the INPUT
statement is executed.
Each time, a number is read in and added to SUM
.
You could improve the program by having it ask the user for
the file name and by using a FOR
loop.
Suggest a way that the program could compute the average of the numbers.